<!-- build time:Tue Jul 21 2020 12:41:23 GMT+0800 (GMT+08:00) --><!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=2"><meta name="theme-color" content="#222"><meta name="generator" content="Hexo 4.2.0"><link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png"><link rel="icon" type="image/png" sizes="32x32" href="/img/blog_favicon/favicon-32x32-next.png"><link rel="icon" type="image/png" sizes="16x16" href="/img/blog_favicon/favicon-16x16-next.png"><link rel="mask-icon" href="/images/logo.svg" color="#222"><meta name="baidu-site-verification" content="r15J5zOS2KI43yBS"><link rel="stylesheet" href="/css/main.css"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"><link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/pace/1.0.2/themes/blue/pace-theme-minimal.min.css"><script src="//cdnjs.cloudflare.com/ajax/libs/pace/1.0.2/pace.min.js"></script><script id="hexo-configurations">var NexT=window.NexT||{},CONFIG={hostname:new URL("http://www.zhengjiaao.cn").hostname,root:"/",scheme:"Muse",version:"7.6.0",exturl:!1,sidebar:{position:"left",display:"post",padding:18,offset:12,onmobile:!1},copycode:{enable:!0,show_result:!0,style:null},back2top:{enable:!0,sidebar:!1,scrollpercent:!0},bookmark:{enable:!0,color:"#222",save:"auto"},fancybox:!0,mediumzoom:!1,lazyload:!1,pangu:!1,comments:{style:"tabs",active:"valine",storage:!0,lazyload:!1,nav:null,activeClass:"valine"},algolia:{appID:"",apiKey:"",indexName:"",hits:{per_page:10},labels:{input_placeholder:"Search for Posts",hits_empty:"We didn't find any results for the search: ${query}",hits_stats:"${hits} results found in ${time} ms"}},localsearch:{enable:!0,trigger:"auto",top_n_per_article:1,unescape:!1,preload:!1},path:"search.xml",motion:{enable:!0,async:!1,transition:{post_block:"fadeIn",post_header:"slideDownIn",post_body:"slideDownIn",coll_header:"slideLeftIn",sidebar:"slideUpIn"}}}</script><meta property="og:type" content="article"><meta property="og:title" content="Windows-Git-安装及使用"><meta property="og:url" content="http://www.zhengjiaao.cn/posts/228604021.html"><meta property="og:site_name" content="宇宙小神特别萌"><meta property="og:locale" content="zh_CN"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-56e5c78cd4b8703d.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-41ffd8c48b1dfacb.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-47fc912a1b1c6c62.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-ed8b875a42ea84dd.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-4b52f2b966fc70bf.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-64e5634202fef3b2.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-2c2850fc0dac4a35.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-9e552cc69f374167.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-271cda506b9747e8.png"><meta property="article:published_time" content="2020-01-03T08:14:51.000Z"><meta property="article:modified_time" content="2020-07-20T10:37:55.323Z"><meta property="article:author" content="宇宙小神特别萌"><meta property="article:tag" content="Git"><meta name="twitter:card" content="summary"><meta name="twitter:image" content="https://upload-images.jianshu.io/upload_images/15645795-56e5c78cd4b8703d.png"><link rel="canonical" href="http://www.zhengjiaao.cn/posts/228604021.html"><script id="page-configurations">CONFIG.page={sidebar:"",isHome:!1,isPost:!0}</script><title>Windows-Git-安装及使用 | 宇宙小神特别萌</title><noscript><style>.sidebar-inner,.use-motion .brand,.use-motion .collection-header,.use-motion .comments,.use-motion .menu-item,.use-motion .pagination,.use-motion .post-block,.use-motion .post-body,.use-motion .post-header{opacity:initial}.use-motion .site-subtitle,.use-motion .site-title{opacity:initial;top:initial}.use-motion .logo-line-before i{left:initial}.use-motion .logo-line-after i{right:initial}</style></noscript><link rel="alternate" href="/atom.xml" title="宇宙小神特别萌" type="application/atom+xml"></head><body itemscope itemtype="http://schema.org/WebPage"><div class="container use-motion"><div class="headband"></div><header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="header-inner"><div class="site-brand-container"><div class="site-meta custom-logo"><div class="site-meta-headline"><a><img class="custom-logo-image" src="/img/blog_favicon/favicon-32x32-next.png" alt="宇宙小神特别萌"></a></div><div><a href="/" class="brand" rel="start"><span class="logo-line-before"><i></i></span> <span class="site-title">宇宙小神特别萌</span> <span class="logo-line-after"><i></i></span></a></div><p class="site-subtitle">ZhengJa</p></div><div class="site-nav-toggle"><div class="toggle" aria-label="切换导航栏"><span class="toggle-line toggle-line-first"></span> <span class="toggle-line toggle-line-middle"></span> <span class="toggle-line toggle-line-last"></span></div></div></div><nav class="site-nav"><ul id="menu" class="menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签<span class="badge">27</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档<span class="badge">116</span></a></li><li class="menu-item menu-item-sitemap"><a href="/sitemap.xml" rel="section"><i class="fa fa-fw fa-sitemap"></i>站点地图</a></li><li class="menu-item menu-item-messageboard"><a href="/messageboard/" rel="section"><i class="fa fa-fw fa-address-book"></i>留言板</a></li><li class="menu-item menu-item-links"><a href="/links/" rel="section"><i class="fa fa-fw fa-user-plus"></i>友链</a></li><li class="menu-item menu-item-shuoshuo"><a href="/shuoshuo/" rel="section"><i class="fa fa-fw fa-file-text-o"></i>说说</a></li><li class="menu-item menu-item-search"><a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索</a></li></ul></nav><div class="site-search"><div class="popup search-popup"><div class="search-header"><span class="search-icon"><i class="fa fa-search"></i></span><div class="search-input-container"><input autocomplete="off" autocorrect="off" autocapitalize="none" placeholder="搜索..." spellcheck="false" type="text" id="search-input"></div><span class="popup-btn-close"><i class="fa fa-times-circle"></i></span></div><div id="search-result"></div></div><div class="search-pop-overlay"></div></div></div></header><div class="back-to-top"><i class="fa fa-arrow-up"></i> <span>0%</span></div><div class="reading-progress-bar"></div><a role="button" class="book-mark-link book-mark-link-fixed"></a> <a href="https://github.com/zhengjiaao" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin:130px 106px" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><main class="main"><div class="main-inner"><div class="content-wrap"><div class="content"><div class="posts-expand"><article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN"><link itemprop="mainEntityOfPage" href="http://www.zhengjiaao.cn/posts/228604021.html"><span hidden itemprop="author" itemscope itemtype="http://schema.org/Person"><meta itemprop="image" content="/my-images/avatar.gif"><meta itemprop="name" content="宇宙小神特别萌"><meta itemprop="description" content="人生就是一次幸运的旅行！"></span><span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization"><meta itemprop="name" content="宇宙小神特别萌"></span><header class="post-header"><h1 class="post-title" itemprop="name headline">Windows-Git-安装及使用</h1><div class="post-meta"><span class="post-meta-item"><span class="post-meta-item-icon"><i class="fa fa-calendar-o"></i> </span><span class="post-meta-item-text">发表于</span> <time title="创建时间：2020-01-03 16:14:51" itemprop="dateCreated datePublished" datetime="2020-01-03T16:14:51+08:00">2020-01-03</time> </span><span class="post-meta-item"><span class="post-meta-item-icon"><i class="fa fa-calendar-check-o"></i> </span><span class="post-meta-item-text">更新于</span> <time title="修改时间：2020-07-20 18:37:55" itemprop="dateModified" datetime="2020-07-20T18:37:55+08:00">2020-07-20</time> </span><span id="/posts/228604021.html" class="post-meta-item leancloud_visitors" data-flag-title="Windows-Git-安装及使用" title="热度"><span class="post-meta-item-icon"><i class="fa fa-eye"></i> </span><span class="post-meta-item-text">热度：</span> <span class="leancloud-visitors-count"></span> <span>℃</span> </span><span class="post-meta-item" title="热度" id="busuanzi_container_page_pv" style="display:none"><span class="post-meta-item-icon"><i class="fa fa-eye"></i> </span><span class="post-meta-item-text">热度：</span> <span id="busuanzi_value_page_pv"></span> </span><span class="post-meta-item"><span class="post-meta-item-icon"><i class="fa fa-comment-o"></i> </span><span class="post-meta-item-text">Valine：</span> <a title="valine" href="/posts/228604021.html#comments" itemprop="discussionUrl"><span class="post-comments-count valine-comment-count" data-xid="/posts/228604021.html" itemprop="commentCount"></span></a></span><br><span class="post-meta-item" title="本文字数"><span class="post-meta-item-icon"><i class="fa fa-file-word-o"></i> </span><span class="post-meta-item-text">本文字数：</span> <span>21k</span> </span><span class="post-meta-item" title="阅读时长"><span class="post-meta-item-icon"><i class="fa fa-clock-o"></i> </span><span class="post-meta-item-text">阅读时长 &asymp;</span> <span>20 分钟</span></span></div></header><div class="post-body" itemprop="articleBody"><meta name="referrer" content="no-referrer"><a id="more"></a><p><img src="https://upload-images.jianshu.io/upload_images/15645795-56e5c78cd4b8703d.png" alt="Windows Git安装及使用 目录.png"><br>追加：7、远程仓库管理</p><p>本片git内容适合：对git了解少的人 ，较适合初级或小白程序员!</p><h3 id="1、git-安装、升级、简单测试"><a href="#1、git-安装、升级、简单测试" class="headerlink" title="1、git 安装、升级、简单测试"></a>1、git 安装、升级、简单测试</h3><p>git安装：<br>描述：windows下载地址：<a href="https://git-scm.com/download/win" target="_blank" rel="noopener">windows git</a> 默认会根据你的电脑下载适合版本类型<br>流程：双击下载的：Git-2.23.0-64-bit.exe –&gt; 一直点击Next就可好(可以更改一下git安装路径).</p><h4 id="git升级："><a href="#git升级：" class="headerlink" title="git升级："></a>git升级：</h4><p>描述：git已经安装 ，想升级到最新版本<br>命令：尝试这两个命令git update 和 git update-git-for-windows</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">#查看当前git版本</span><br><span class="line">$ git version</span><br><span class="line">git version <span class="number">2</span>.<span class="number">20</span>.<span class="number">1</span>.windows.<span class="number">1</span></span><br><span class="line"></span><br><span class="line">#升级git到最新本版 再输入 "y"</span><br><span class="line">$ git update</span><br><span class="line">#升级git到最新本版 再输入 "y"</span><br><span class="line">$ git update-git-<span class="keyword">for</span>-windows</span><br><span class="line"></span><br><span class="line">#查看升级后的git版本</span><br><span class="line">$ git version</span><br><span class="line">git version <span class="number">2</span>.<span class="number">24</span>.<span class="number">0</span>.windows.<span class="number">1</span></span><br></pre></td></tr></table></figure><blockquote><p>下载的新版本git的安装路径 ，默认是旧版本的安装地址</p></blockquote><h4 id="配置git的户信息："><a href="#配置git的户信息：" class="headerlink" title="配置git的户信息："></a>配置git的户信息：</h4><p>命令：</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">#右击鼠标--&gt;Git Bash Here 输入命令</span><br><span class="line">#配置git用户名：随便起 ，最好好写成自己的拼音名字 ，这样提交代码到远程仓库 ，别人知道是你提交的</span><br><span class="line">$ git config --global user.name "ZhengJa"</span><br><span class="line">#配置git邮箱：邮箱格式要对 ，不要求邮箱是真的</span><br><span class="line">$ git config --global user.email "<span class="number">953649948</span>@qq.com"</span><br></pre></td></tr></table></figure><p>命令演示:</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line">Administrator@ZhengJiaAo MINGW64 ~/Desktop</span><br><span class="line">#git配置用户名</span><br><span class="line">$ git config --global user.name "ZhengJa"</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 ~/Desktop</span><br><span class="line">#查询配置的用户名</span><br><span class="line">$ git config user.name</span><br><span class="line">ZhengJa</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 ~/Desktop</span><br><span class="line">#git配置邮箱</span><br><span class="line">$ git config --global user.email "<span class="number">953649948</span>@qq.com"</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 ~/Desktop</span><br><span class="line">#查询配置的邮箱</span><br><span class="line">$ git config user.email</span><br><span class="line"><span class="number">953649948</span>@qq.com</span><br><span class="line">Administrator@ZhengJiaAo MINGW64 ~/Desktop</span><br><span class="line">#查询git的所有配置信息</span><br><span class="line">$ git config --list</span><br><span class="line">core.symlinks=false</span><br><span class="line">core.autocrlf=true</span><br><span class="line">core.fscache=true</span><br><span class="line"><span class="built_in">color</span>.diff=auto</span><br><span class="line"><span class="built_in">color</span>.status=auto</span><br><span class="line"><span class="built_in">color</span>.branch=auto</span><br><span class="line"><span class="built_in">color</span>.interactive=true</span><br><span class="line"><span class="built_in">help</span>.<span class="built_in">format</span>=html</span><br><span class="line">rebase.autosquash=true</span><br><span class="line">http.sslcainfo=D:/Git/mingw64/ssl/certs/ca-bundle.crt</span><br><span class="line">http.sslbackend=openssl</span><br><span class="line">diff.astextplain.textconv=astextplain</span><br><span class="line">filter.lfs.clean=git-lfs clean -- %f</span><br><span class="line">filter.lfs.smudge=git-lfs smudge -- %f</span><br><span class="line">filter.lfs.process=git-lfs filter-process</span><br><span class="line">filter.lfs.required=true</span><br><span class="line">credential.helper=manager</span><br><span class="line">user.name=ZhengJa</span><br><span class="line">user.email=<span class="number">953649948</span>@qq.com</span><br><span class="line">ssh.variant=ssh</span><br></pre></td></tr></table></figure><p>git安装及配置已经完成!<br>(可选)git客户端安装:<a href="https://www.sourcetreeapp.com/" target="_blank" rel="noopener">sourcetree 官网下载</a> 点击–&gt;Download for Windows</p><h4 id="git本地测试："><a href="#git本地测试：" class="headerlink" title="git本地测试："></a>git本地测试：</h4><p>创建一个demo文件夹 ，作为演示的本地仓库。此git工作流并没有与远程仓库做关联！<br>流程：创建文件test.txt–&gt;添加至暂存区–&gt;将暂存区内容commit到本地仓库</p><p>命令：</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">#初始化本版库</span><br><span class="line">git init</span><br><span class="line"></span><br><span class="line">#添加文件到版本库 ，添加某个文件 git add test.txt  添加所有 git add .</span><br><span class="line">git add </span><br><span class="line">git commit -m "提交信息"</span><br><span class="line"></span><br><span class="line">#查看仓库状态</span><br><span class="line">git status</span><br></pre></td></tr></table></figure><p>命令演示：</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br></pre></td><td class="code"><pre><span class="line">Administrator@ZhengJiaAo MINGW64 /j/testfile</span><br><span class="line">#进入一个干净的文件夹--&gt;testfile</span><br><span class="line">$ ls</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/testfile</span><br><span class="line">#创建一个文件夹</span><br><span class="line">$ <span class="built_in">mkdir</span> demo</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/testfile</span><br><span class="line">#进入刚刚创建的文件夹</span><br><span class="line">$ <span class="built_in">cd</span> demo</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/testfile/demo</span><br><span class="line">#查看 ，文件夹中没有任何内容</span><br><span class="line">$ ll</span><br><span class="line">total <span class="number">0</span></span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/testfile/demo</span><br><span class="line">#初始化git</span><br><span class="line">$ git init</span><br><span class="line">Initialized empty Git repository <span class="keyword">in</span> J:/testfile/demo/.git/</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/testfile/demo (master)</span><br><span class="line">#查看 可以看出生成了一个 .git文件夹 ，说明初始化git仓库成功</span><br><span class="line">$ ls -a</span><br><span class="line">./  ../  .git/</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/testfile/demo (master)</span><br><span class="line">#将"git repo" &gt;&gt; 追加进test.txt文件</span><br><span class="line">$ <span class="built_in">echo</span> "git repo" &gt;&gt; test.txt</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/testfile/demo (master)</span><br><span class="line">#查看test.txt文件内容</span><br><span class="line">$ cat test.txt</span><br><span class="line">git repo</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/testfile/demo (master)</span><br><span class="line">#git 将test文件添加到暂存区</span><br><span class="line">$ git add test.txt</span><br><span class="line"><span class="function">warning: <span class="title">LF</span> <span class="title">will</span> <span class="title">be</span> <span class="title">replaced</span> <span class="title">by</span> <span class="title">CRLF</span> <span class="title">in</span> <span class="title">test.txt</span>.</span></span><br><span class="line"><span class="function"><span class="title">The</span> <span class="title">file</span> <span class="title">will</span> <span class="title">have</span> <span class="title">its</span> <span class="title">original</span> <span class="title">line</span> <span class="title">endings</span> <span class="title">in</span> <span class="title">your</span> <span class="title">working</span> <span class="title">directory</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function"><span class="title">Administrator</span>@<span class="title">ZhengJiaAo</span> <span class="title">MINGW64</span> /<span class="title">j</span>/<span class="title">testfile</span>/<span class="title">demo</span> (<span class="title">master</span>)</span></span><br><span class="line"><span class="function">#<span class="title">git</span> <span class="title">commit</span> 暂存区文件提交到本地本库</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">commit</span> -<span class="title">m</span> "<span class="title">repo</span> <span class="title">first</span> <span class="title">commit</span>"</span></span><br><span class="line"><span class="function">[<span class="title">master</span> (<span class="title">root</span>-<span class="title">commit</span>) 3337810] <span class="title">repo</span> <span class="title">first</span> <span class="title">commit</span></span></span><br><span class="line"><span class="function"> 1 <span class="title">file</span> <span class="title">changed</span>, 1 <span class="title">insertion</span>(+)</span></span><br><span class="line"><span class="function"> <span class="title">create</span> <span class="title">mode</span> 100644 <span class="title">test.txt</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function"><span class="title">Administrator</span>@<span class="title">ZhengJiaAo</span> <span class="title">MINGW64</span> /<span class="title">j</span>/<span class="title">testfile</span>/<span class="title">demo</span> (<span class="title">master</span>)</span></span><br><span class="line"><span class="function">#查看状态 ，说明现在都已提交到本地仓库 ，暂存区是干净的</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">status</span></span></span><br><span class="line"><span class="function"><span class="title">On</span> <span class="title">branch</span> <span class="title">master</span></span></span><br><span class="line"><span class="function"><span class="title">nothing</span> <span class="title">to</span> <span class="title">commit</span>, <span class="title">working</span> <span class="title">tree</span> <span class="title">clean</span></span></span><br></pre></td></tr></table></figure><h4 id="解决git-bash-终端显示中文乱码"><a href="#解决git-bash-终端显示中文乱码" class="headerlink" title="解决git bash 终端显示中文乱码"></a>解决git bash 终端显示中文乱码</h4><p>在git bash的界面中右击空白处 ，弹出菜单 ，选择选项-&gt;文本-&gt;本地Locale ，设置为zh_CN ，而旁边的字符集选框选为UTF-8。</p><p>英文显示则是：<br>Options-&gt;Text-&gt;Locale改为zh_CN ，Character set改为UTF-8</p><h3 id="2、git工作流"><a href="#2、git工作流" class="headerlink" title="2、git工作流"></a>2、git工作流</h3><p>工作流图：<br><img src="https://upload-images.jianshu.io/upload_images/15645795-41ffd8c48b1dfacb.png" alt="工作流图.png"></p><p>创建一个demo2文件夹 ，作为演示的本地仓库。此git工作流并没有与远程仓库做关联！</p><h4 id="前提：查看commit日志："><a href="#前提：查看commit日志：" class="headerlink" title="前提：查看commit日志："></a>前提：查看commit日志：</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git log --oneline    	 &#x2F;&#x2F;查看commit提交列表：commit_Id</span><br><span class="line">git log   &#x2F;&#x2F;commit详细信息</span><br></pre></td></tr></table></figure><h4 id="1、文件commit本地仓库"><a href="#1、文件commit本地仓库" class="headerlink" title="1、文件commit本地仓库"></a>1、文件commit本地仓库</h4><p>流程1：创建一个文件demo2_test.txt–&gt;添加文件到暂存区–&gt;将暂存区内容保存到本地仓库</p><p>命令：</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">#初始化git版本库</span><br><span class="line">git init</span><br><span class="line"></span><br><span class="line">#将文件添加到暂存区</span><br><span class="line">git add </span><br><span class="line"></span><br><span class="line">#将暂存区的文件提交到本地仓库</span><br><span class="line">git commit -m "提交描述信息"</span><br></pre></td></tr></table></figure><p>命令演示：</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br></pre></td><td class="code"><pre><span class="line">Administrator@ZhengJiaAo MINGW64 /j/testfile</span><br><span class="line">#进入一个干净的文件夹--&gt;testfile</span><br><span class="line">$ ls</span><br><span class="line">demo/</span><br><span class="line"></span><br><span class="line">#创建一个文件夹demo2</span><br><span class="line">$ <span class="built_in">mkdir</span> demo2</span><br><span class="line"></span><br><span class="line">#进入刚刚创建的文件夹</span><br><span class="line">$ <span class="built_in">cd</span> demo2</span><br><span class="line"></span><br><span class="line">#查看 ，文件夹中没有任何内容</span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/testfile/demo2</span><br><span class="line">$ ll</span><br><span class="line">total <span class="number">0</span></span><br><span class="line"></span><br><span class="line">#初始化git</span><br><span class="line">$ git init</span><br><span class="line">Initialized empty Git repository <span class="keyword">in</span> J:/testfile/demo2/.git/</span><br><span class="line"></span><br><span class="line">#添加内容到demo2_test.txt文件</span><br><span class="line">$ <span class="built_in">echo</span> "第一天需求" &gt;&gt; demo2_test.txt</span><br><span class="line"></span><br><span class="line">#查看文件内容</span><br><span class="line">$ cat demo2_test.txt</span><br><span class="line">第一天需求</span><br><span class="line"></span><br><span class="line">#查看状态：demo2_test.txt  为红色字体 ，说明文件还没有添加到暂存区</span><br><span class="line">$ git status</span><br><span class="line">On branch master</span><br><span class="line">No commits yet</span><br><span class="line">Untracked files:</span><br><span class="line">  (use "git add &lt;file&gt;..." to include <span class="keyword">in</span> what will be committed)</span><br><span class="line">        demo2_test.txt</span><br><span class="line">nothing added to commit but untracked files present (use "git add" to track)</span><br><span class="line"></span><br><span class="line">#将文件添加到暂存区</span><br><span class="line">$ git add demo2_test.txt</span><br><span class="line"><span class="function">warning: <span class="title">LF</span> <span class="title">will</span> <span class="title">be</span> <span class="title">replaced</span> <span class="title">by</span> <span class="title">CRLF</span> <span class="title">in</span> <span class="title">demo2_test.txt</span>.</span></span><br><span class="line"><span class="function"><span class="title">The</span> <span class="title">file</span> <span class="title">will</span> <span class="title">have</span> <span class="title">its</span> <span class="title">original</span> <span class="title">line</span> <span class="title">endings</span> <span class="title">in</span> <span class="title">your</span> <span class="title">working</span> <span class="title">directory</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#查看状态： <span class="title">demo2_test.txt</span>字体变成绿色 ，说明文件已添加到暂存区 ，再将文件提交到本地仓库</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">status</span></span></span><br><span class="line"><span class="function"><span class="title">On</span> <span class="title">branch</span> <span class="title">master</span></span></span><br><span class="line"><span class="function"><span class="title">No</span> <span class="title">commits</span> <span class="title">yet</span></span></span><br><span class="line"><span class="function"><span class="title">Changes</span> <span class="title">to</span> <span class="title">be</span> <span class="title">committed</span>:</span></span><br><span class="line"><span class="function">  (<span class="title">use</span> "<span class="title">git</span> <span class="title">rm</span> --<span class="title">cached</span> &lt;<span class="title">file</span>&gt;..." <span class="title">to</span> <span class="title">unstage</span>)</span></span><br><span class="line"><span class="function">        <span class="title">new</span> <span class="title">file</span>:   <span class="title">demo2_test.txt</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#将暂存区的文件提交到本地仓库</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">commit</span> -<span class="title">m</span> "<span class="title">first</span>-<span class="title">commit</span>:新增<span class="title">demo2_test.txt</span>文件"</span></span><br><span class="line"><span class="function">[<span class="title">master</span> (<span class="title">root</span>-<span class="title">commit</span>) 970<span class="title">eca2</span>] <span class="title">first</span>-<span class="title">commit</span>:新增<span class="title">demo2_test.txt</span>文件</span></span><br><span class="line"><span class="function"> 1 <span class="title">file</span> <span class="title">changed</span>, 1 <span class="title">insertion</span>(+)</span></span><br><span class="line"><span class="function"> <span class="title">create</span> <span class="title">mode</span> 100644 <span class="title">demo2_test.txt</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#说明暂存区没有文件 ，且所有修改或添加的文件都已经提交到本地仓库</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">status</span></span></span><br><span class="line"><span class="function"><span class="title">On</span> <span class="title">branch</span> <span class="title">master</span></span></span><br><span class="line"><span class="function"><span class="title">nothing</span> <span class="title">to</span> <span class="title">commit</span>, <span class="title">working</span> <span class="title">tree</span> <span class="title">clean</span></span></span><br></pre></td></tr></table></figure><h4 id="2、将暂存区回退到工作区-回退修改内容"><a href="#2、将暂存区回退到工作区-回退修改内容" class="headerlink" title="2、将暂存区回退到工作区 回退修改内容"></a>2、将暂存区回退到工作区 回退修改内容</h4><p><strong>流程2：修改demo2_test.txt文件内容–&gt;将文件到暂存区–&gt;将文件从暂存区移除–&gt;回退修改的文件内容</strong></p><p>命令：</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">#将暂存区的文件移除</span><br><span class="line">git reset HEAD demo2_test.txt</span><br><span class="line"></span><br><span class="line">#将文件修改的内容回退,就是让这个文件回到最近一次git commit或git add时的状态 ，git checkout – filename 可以丢弃某个文件在工作区的改动</span><br><span class="line">git checkout -- demo2_test.txt</span><br></pre></td></tr></table></figure><p>命令演示：</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br></pre></td><td class="code"><pre><span class="line">Administrator@ZhengJiaAo MINGW64 /j/testfile/demo2 (master)</span><br><span class="line">#向文件追加内容</span><br><span class="line">$  <span class="built_in">echo</span> "第一天：追加的需求" &gt;&gt; demo2_test.txt</span><br><span class="line"></span><br><span class="line">#查看文件内容</span><br><span class="line">$ cat demo2_test.txt</span><br><span class="line">第一天需求</span><br><span class="line">第一天：追加的需求</span><br><span class="line"></span><br><span class="line">#查看状态：demo2_test.txt 字体是红色 ，说明还没有添加到暂存区 ，将文件添加到暂存区</span><br><span class="line">$ git status</span><br><span class="line">On branch master</span><br><span class="line">Changes <span class="keyword">not</span> staged <span class="keyword">for</span> commit:</span><br><span class="line">  (use "git add &lt;file&gt;..." to update what will be committed)</span><br><span class="line">  (use "git checkout -- &lt;file&gt;..." to discard changes <span class="keyword">in</span> working directory)</span><br><span class="line"><span class="function">        modified:   <span class="title">demo2_test.txt</span></span></span><br><span class="line"><span class="function"><span class="title">no</span> <span class="title">changes</span> <span class="title">added</span> <span class="title">to</span> <span class="title">commit</span> (<span class="title">use</span> "<span class="title">git</span> <span class="title">add</span>" <span class="title">and</span>/<span class="title">or</span> "<span class="title">git</span> <span class="title">commit</span> -<span class="title">a</span>")</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#添加文件到暂存区</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">add</span> <span class="title">demo2_test.txt</span></span></span><br><span class="line"><span class="function"><span class="title">warning</span>: <span class="title">LF</span> <span class="title">will</span> <span class="title">be</span> <span class="title">replaced</span> <span class="title">by</span> <span class="title">CRLF</span> <span class="title">in</span> <span class="title">demo2_test.txt</span>.</span></span><br><span class="line"><span class="function"><span class="title">The</span> <span class="title">file</span> <span class="title">will</span> <span class="title">have</span> <span class="title">its</span> <span class="title">original</span> <span class="title">line</span> <span class="title">endings</span> <span class="title">in</span> <span class="title">your</span> <span class="title">working</span> <span class="title">directory</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#查看状态：<span class="title">demo2_test.txt</span> 字体变成绿色 ，说明文件已在暂存区</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">status</span></span></span><br><span class="line"><span class="function"><span class="title">On</span> <span class="title">branch</span> <span class="title">master</span></span></span><br><span class="line"><span class="function"><span class="title">Changes</span> <span class="title">to</span> <span class="title">be</span> <span class="title">committed</span>:</span></span><br><span class="line"><span class="function">  (<span class="title">use</span> "<span class="title">git</span> <span class="title">reset</span> <span class="title">HEAD</span> &lt;<span class="title">file</span>&gt;..." <span class="title">to</span> <span class="title">unstage</span>)</span></span><br><span class="line"><span class="function">        <span class="title">modified</span>:   <span class="title">demo2_test.txt</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#将暂存区的文件移除</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">reset</span> <span class="title">HEAD</span> <span class="title">demo2_test.txt</span></span></span><br><span class="line"><span class="function"><span class="title">Unstaged</span> <span class="title">changes</span> <span class="title">after</span> <span class="title">reset</span>:</span></span><br><span class="line"><span class="function"><span class="title">M</span>       <span class="title">demo2_test.txt</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#查看状态：<span class="title">demo2_test.txt</span>字体变成红色</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">status</span></span></span><br><span class="line"><span class="function"><span class="title">On</span> <span class="title">branch</span> <span class="title">master</span></span></span><br><span class="line"><span class="function"><span class="title">Changes</span> <span class="title">not</span> <span class="title">staged</span> <span class="title">for</span> <span class="title">commit</span>:</span></span><br><span class="line"><span class="function">  (<span class="title">use</span> "<span class="title">git</span> <span class="title">add</span> &lt;<span class="title">file</span>&gt;..." <span class="title">to</span> <span class="title">update</span> <span class="title">what</span> <span class="title">will</span> <span class="title">be</span> <span class="title">committed</span>)</span></span><br><span class="line"><span class="function">  (<span class="title">use</span> "<span class="title">git</span> <span class="title">checkout</span> -- &lt;<span class="title">file</span>&gt;..." <span class="title">to</span> <span class="title">discard</span> <span class="title">changes</span> <span class="title">in</span> <span class="title">working</span> <span class="title">directory</span>)</span></span><br><span class="line"><span class="function">        <span class="title">modified</span>:   <span class="title">demo2_test.txt</span></span></span><br><span class="line"><span class="function"><span class="title">no</span> <span class="title">changes</span> <span class="title">added</span> <span class="title">to</span> <span class="title">commit</span> (<span class="title">use</span> "<span class="title">git</span> <span class="title">add</span>" <span class="title">and</span>/<span class="title">or</span> "<span class="title">git</span> <span class="title">commit</span> -<span class="title">a</span>")</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#查看文件内容</span></span><br><span class="line"><span class="function">$ <span class="title">cat</span> <span class="title">demo2_test.txt</span></span></span><br><span class="line"><span class="function">第一天需求</span></span><br><span class="line"><span class="function">第一天：追加的需求</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#将文件修改的内容回退</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">checkout</span> -- <span class="title">demo2_test.txt</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#回退文件修改的内容</span></span><br><span class="line"><span class="function">$ <span class="title">cat</span> <span class="title">demo2_test.txt</span></span></span><br><span class="line"><span class="function">第一天需求</span></span><br></pre></td></tr></table></figure><h4 id="3、把最近一次commit撤回到暂存区"><a href="#3、把最近一次commit撤回到暂存区" class="headerlink" title="3、把最近一次commit撤回到暂存区"></a>3、把最近一次commit撤回到暂存区</h4><p>命令：</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">#查看版本库状态</span><br><span class="line">$ git status</span><br><span class="line">#查看commit日志</span><br><span class="line">$ git log --oneline</span><br><span class="line">#把最近的一次commit撤回到暂存区</span><br><span class="line">$ git reset --soft HEAD^</span><br><span class="line">$ git status</span><br></pre></td></tr></table></figure><p>命令演示：</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">#添加文件并追加内容 "第一次修改"</span><br><span class="line">$ <span class="built_in">echo</span> "第一次修改" &gt;&gt; demo2_test.txt</span><br><span class="line">#添加到暂存区</span><br><span class="line">$ git add demo2_test.txt</span><br><span class="line">#查看状态：绿色</span><br><span class="line">$ git status</span><br><span class="line">On branch master</span><br><span class="line">Changes to be committed:</span><br><span class="line">  (use "git <span class="built_in">restore</span> --staged &lt;file&gt;..." to unstage)</span><br><span class="line">        new file:   demo2_test.txt</span><br><span class="line">#commit提交</span><br><span class="line">$ git commit -m "第一次提交文件"</span><br><span class="line">[master <span class="number">507</span>c25c] 第一次提交文件</span><br><span class="line"> <span class="number">1</span> file changed, <span class="number">1</span> insertion(+)</span><br><span class="line"> create <span class="built_in">mode</span> <span class="number">100644</span> demo2_test.txt</span><br><span class="line">#查看状态：说明所有暂存区的内容已被提交</span><br><span class="line">$ git status</span><br><span class="line">On branch master</span><br><span class="line">nothing to commit, working <span class="built_in">tree</span> clean</span><br><span class="line">#查看commit日志</span><br><span class="line">$ git log --oneline</span><br><span class="line"><span class="number">608</span>e471 (HEAD -&gt; master) 第一次提交文件</span><br><span class="line"></span><br><span class="line">#把最近的一次commit撤回到暂存区</span><br><span class="line">$ git reset --soft HEAD^</span><br><span class="line"></span><br><span class="line">#查看状态：demo2_test.txt颜色绿色 ，已回退到暂存区</span><br><span class="line">$ git status</span><br><span class="line">On branch master</span><br><span class="line">Changes to be committed:</span><br><span class="line">  (use "git <span class="built_in">restore</span> --staged &lt;file&gt;..." to unstage)</span><br><span class="line">        new file:   demo2_test.txt</span><br></pre></td></tr></table></figure><h4 id="4、回退本地版本库commit提交"><a href="#4、回退本地版本库commit提交" class="headerlink" title="4、回退本地版本库commit提交"></a>4、回退本地版本库commit提交</h4><p>流程3：修改demo2_test.txt文件内容–&gt;将文件到暂存区–&gt;暂存区内容commit提交–&gt;回退commit提交内容</p><p>命令：</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">#查看日志：commit提交日志</span><br><span class="line">$ git log</span><br><span class="line">$ git log --oneline</span><br><span class="line"></span><br><span class="line">#回退commit提交：回到某次commit提交</span><br><span class="line">$ git reset --hard commit_Id</span><br></pre></td></tr></table></figure><p>命令演示：</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line">Administrator@ZhengJiaAo MINGW64 /j/testfile/demo2 (master)</span><br><span class="line">#查看文件内容</span><br><span class="line">$ cat demo2_test.txt</span><br><span class="line">第一天需求</span><br><span class="line"></span><br><span class="line">#追加内容到文件</span><br><span class="line">$ <span class="built_in">echo</span> "第二天需求" &gt;&gt; demo2_test.txt</span><br><span class="line"></span><br><span class="line">#查看文件内容</span><br><span class="line">$ cat demo2_test.txt</span><br><span class="line">第一天需求</span><br><span class="line">第二天需求</span><br><span class="line"></span><br><span class="line">#将文件添加到暂存区</span><br><span class="line">$ git add demo2_test.txt</span><br><span class="line"><span class="function">warning: <span class="title">LF</span> <span class="title">will</span> <span class="title">be</span> <span class="title">replaced</span> <span class="title">by</span> <span class="title">CRLF</span> <span class="title">in</span> <span class="title">demo2_test.txt</span>.</span></span><br><span class="line"><span class="function"><span class="title">The</span> <span class="title">file</span> <span class="title">will</span> <span class="title">have</span> <span class="title">its</span> <span class="title">original</span> <span class="title">line</span> <span class="title">endings</span> <span class="title">in</span> <span class="title">your</span> <span class="title">working</span> <span class="title">directory</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#将暂存区内容<span class="title">commit</span>提交至本地仓库</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">commit</span> -<span class="title">m</span> "<span class="title">commit</span>:修改<span class="title">demo2_test.txt</span>"</span></span><br><span class="line"><span class="function">[<span class="title">master</span> <span class="title">a6d8085</span>] <span class="title">commit</span>:修改<span class="title">demo2_test.txt</span></span></span><br><span class="line"><span class="function"> 1 <span class="title">file</span> <span class="title">changed</span>, 1 <span class="title">insertion</span>(+)</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#查看日志：<span class="title">commit</span>提交日志 ，可以看出有两次提交信息 ，现在想回到之前的“第一天需求” ，“第二天需求“不需要了</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">log</span></span></span><br><span class="line"><span class="function"><span class="title">commit</span> <span class="title">a6d8085e0c5e4ad6815c80128eb603132077ca9e</span> (<span class="title">HEAD</span> -&gt; <span class="title">master</span>)</span></span><br><span class="line"><span class="function"><span class="title">Author</span>: <span class="title">ZhengJa</span> &lt;953649948@<span class="title">qq.com</span>&gt;</span></span><br><span class="line"><span class="function"><span class="title">Date</span>:   <span class="title">Thu</span> <span class="title">Oct</span> 17 12:52:57 2019 +0800</span></span><br><span class="line"><span class="function">    <span class="title">commit</span>:修改<span class="title">demo2_test.txt</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function"><span class="title">commit</span> 970<span class="title">eca211415c4015143895ad1c8585f55298d00</span></span></span><br><span class="line"><span class="function"><span class="title">Author</span>: <span class="title">ZhengJa</span> &lt;953649948@<span class="title">qq.com</span>&gt;</span></span><br><span class="line"><span class="function"><span class="title">Date</span>:   <span class="title">Thu</span> <span class="title">Oct</span> 17 11:25:25 2019 +0800</span></span><br><span class="line"><span class="function">    <span class="title">first</span>-<span class="title">commit</span>:新增<span class="title">demo2_test.txt</span>文件：第一天需求</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#回退<span class="title">commit</span>提交：回到 ”第一天需求”</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">reset</span> --<span class="title">hard</span> 970<span class="title">eca211415c4015143895ad1c8585f55298d00</span></span></span><br><span class="line"><span class="function"><span class="title">HEAD</span> <span class="title">is</span> <span class="title">now</span> <span class="title">at</span> 970<span class="title">eca2</span> <span class="title">first</span>-<span class="title">commit</span>:新增<span class="title">demo2_test.txt</span>文件：第一天需求</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#查看状态</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">status</span></span></span><br><span class="line"><span class="function"><span class="title">On</span> <span class="title">branch</span> <span class="title">master</span></span></span><br><span class="line"><span class="function"><span class="title">nothing</span> <span class="title">to</span> <span class="title">commit</span>, <span class="title">working</span> <span class="title">tree</span> <span class="title">clean</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#查看文件内容</span></span><br><span class="line"><span class="function">$ <span class="title">cat</span> <span class="title">demo2_test.txt</span></span></span><br><span class="line"><span class="function">第一天需求</span></span><br></pre></td></tr></table></figure><blockquote><p>注：</p><p>1、git reset和git revert 效果一样 ，但区别很大<br>git reset ：是回退commit未推动到远程仓库的版本<br>git revert ：是撤退远程仓库已存在的commit版本</p></blockquote><h4 id="5、回退已push到远程版本库commit提交"><a href="#5、回退已push到远程版本库commit提交" class="headerlink" title="5、回退已push到远程版本库commit提交"></a>5、回退已push到远程版本库commit提交</h4><p>命令</p><blockquote><p>git log –oneline //查看commit提交列表：commit_Id</p><p>git revert HEAD //撤销最近一次提交<br>git revert HEAD~1 //撤销上上次的提交 ，注意：数字从0开始<br>git revert 0ffaacc //撤销0ffaacc这次提交</p></blockquote><p>命令演示：</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br></pre></td><td class="code"><pre><span class="line">#文件追加内容</span><br><span class="line">$ <span class="built_in">echo</span> "追加的内容<span class="number">2</span>" &gt;&gt; gittest.txt</span><br><span class="line">#查看文件内容</span><br><span class="line">$ cat gittest.txt</span><br><span class="line">追加的内容<span class="number">1</span></span><br><span class="line">追加的内容<span class="number">2</span></span><br><span class="line"></span><br><span class="line">#添加修改内容到暂存区</span><br><span class="line">$ git add gittest.txt</span><br><span class="line"><span class="function">warning: <span class="title">LF</span> <span class="title">will</span> <span class="title">be</span> <span class="title">replaced</span> <span class="title">by</span> <span class="title">CRLF</span> <span class="title">in</span> <span class="title">gittest.txt</span>.</span></span><br><span class="line"><span class="function"><span class="title">The</span> <span class="title">file</span> <span class="title">will</span> <span class="title">have</span> <span class="title">its</span> <span class="title">original</span> <span class="title">line</span> <span class="title">endings</span> <span class="title">in</span> <span class="title">your</span> <span class="title">working</span> <span class="title">directory</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#<span class="title">commit</span>提交到本地仓库</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">commit</span> -<span class="title">m</span> "提交：追加的内容2"</span></span><br><span class="line"><span class="function">[<span class="title">master</span> 37009<span class="title">fc</span>] 提交：追加的内容2</span></span><br><span class="line"><span class="function"> 1 <span class="title">file</span> <span class="title">changed</span>, 1 <span class="title">insertion</span>(+)</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#将<span class="title">commit</span> <span class="title">push</span>到远程仓库</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">push</span></span></span><br><span class="line"><span class="function"><span class="title">Enumerating</span> <span class="title">objects</span>: 5, <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Counting</span> <span class="title">objects</span>: 100% (5/5), <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Delta</span> <span class="title">compression</span> <span class="title">using</span> <span class="title">up</span> <span class="title">to</span> 4 <span class="title">threads</span></span></span><br><span class="line"><span class="function"><span class="title">Compressing</span> <span class="title">objects</span>: 100% (2/2), <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Writing</span> <span class="title">objects</span>: 100% (3/3), 354 <span class="title">bytes</span> | 177.00 <span class="title">KiB</span>/<span class="title">s</span>, <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Total</span> 3 (<span class="title">delta</span> 0), <span class="title">reused</span> 0 (<span class="title">delta</span> 0)</span></span><br><span class="line"><span class="function"><span class="title">To</span> <span class="title">https</span>://<span class="title">github.com</span>/<span class="title">zhengjiaao</span>/<span class="title">git_test.git</span></span></span><br><span class="line"><span class="function">   6<span class="title">ee6810</span>..37009<span class="title">fc</span>  <span class="title">master</span> -&gt; <span class="title">master</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#查看<span class="title">commit</span>历史记录</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">log</span> --<span class="title">oneline</span></span></span><br><span class="line"><span class="function">37009<span class="title">fc</span> (<span class="title">HEAD</span> -&gt; <span class="title">master</span>, <span class="title">origin</span>/<span class="title">master</span>, <span class="title">origin</span>/<span class="title">HEAD</span>) 提交：追加的内容2</span></span><br><span class="line"><span class="function">7<span class="title">dcf51a</span> 提交：追加的内容1</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#撤销最近一次<span class="title">commit</span> ，进入编辑状态 ，英文 <span class="title">ZZ</span> 退出并保存编辑</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">revert</span> 37009<span class="title">fc</span></span></span><br><span class="line"><span class="function"><span class="title">hint</span>: <span class="title">Waiting</span> <span class="title">for</span> <span class="title">your</span> <span class="title">editor</span> <span class="title">to</span> <span class="title">close</span> <span class="title">the</span> <span class="title">file</span>... <span class="title">error</span>: <span class="title">There</span> <span class="title">was</span> <span class="title">a</span> <span class="title">problem</span> <span class="title">with</span> <span class="title">the</span> <span class="title">editor</span> '<span class="title">vi</span>'.</span></span><br><span class="line"><span class="function"><span class="title">Please</span> <span class="title">supply</span> <span class="title">the</span> <span class="title">message</span> <span class="title">using</span> <span class="title">either</span> -<span class="title">m</span> <span class="title">or</span> -<span class="title">F</span> <span class="title">option</span>.</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#查看文件内容 ，发现"追加的内容2"内容已经不存在</span></span><br><span class="line"><span class="function">$ <span class="title">cat</span> <span class="title">gittest.txt</span></span></span><br><span class="line"><span class="function">追加的内容1</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#将新的版本提交到远程仓库</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">commit</span> -<span class="title">m</span> "撤销<span class="title">gittest</span>文件 追加的内容2"</span></span><br><span class="line"><span class="function">[<span class="title">master</span> <span class="title">a13e1ae</span>] 撤销<span class="title">gittest</span>文件 追加的内容2</span></span><br><span class="line"><span class="function"> 1 <span class="title">file</span> <span class="title">changed</span>, 1 <span class="title">deletion</span>(-)</span></span><br><span class="line"><span class="function">#提交到远程仓库</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">push</span></span></span><br><span class="line"><span class="function"><span class="title">Enumerating</span> <span class="title">objects</span>: 5, <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Counting</span> <span class="title">objects</span>: 100% (5/5), <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Delta</span> <span class="title">compression</span> <span class="title">using</span> <span class="title">up</span> <span class="title">to</span> 4 <span class="title">threads</span></span></span><br><span class="line"><span class="function"><span class="title">Compressing</span> <span class="title">objects</span>: 100% (2/2), <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Writing</span> <span class="title">objects</span>: 100% (3/3), 362 <span class="title">bytes</span> | 181.00 <span class="title">KiB</span>/<span class="title">s</span>, <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Total</span> 3 (<span class="title">delta</span> 0), <span class="title">reused</span> 0 (<span class="title">delta</span> 0)</span></span><br><span class="line"><span class="function"><span class="title">To</span> <span class="title">https</span>://<span class="title">github.com</span>/<span class="title">zhengjiaao</span>/<span class="title">git_test.git</span></span></span><br><span class="line"><span class="function">   37009<span class="title">fc</span>..<span class="title">a13e1ae</span>  <span class="title">master</span> -&gt; <span class="title">master</span></span></span><br></pre></td></tr></table></figure><h4 id="6、清空或删除本地仓库文件"><a href="#6、清空或删除本地仓库文件" class="headerlink" title="6、清空或删除本地仓库文件"></a>6、清空或删除本地仓库文件</h4><p>命令：</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">#删除本地工作区或文件</span><br><span class="line">git rm demo2_test.txt</span><br><span class="line"></span><br><span class="line">#提交删除记录 commit</span><br><span class="line">git commit -m "commit:delete demo2_test.txt文件"</span><br></pre></td></tr></table></figure><p>命令演示：</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line">Administrator@ZhengJiaAo MINGW64 /j/testfile/demo2 (master)</span><br><span class="line">#查看文件内容</span><br><span class="line">$ cat demo2_test.txt</span><br><span class="line">第一天需求</span><br><span class="line"></span><br><span class="line">#查看状态</span><br><span class="line">$ git status</span><br><span class="line">On branch master</span><br><span class="line">nothing to commit, working <span class="built_in">tree</span> clean</span><br><span class="line"></span><br><span class="line">#查看文件个数：<span class="number">1</span></span><br><span class="line">$ ll</span><br><span class="line">total <span class="number">1</span></span><br><span class="line">-rw-r--r-- <span class="number">1</span> Administrator <span class="number">197121</span> <span class="number">17</span> <span class="number">10</span>月 <span class="number">17</span> <span class="number">12</span>:<span class="number">54</span> demo2_test.txt</span><br><span class="line"></span><br><span class="line">#删除本地文件</span><br><span class="line">$ git rm demo2_test.txt</span><br><span class="line">rm 'demo2_test.txt'</span><br><span class="line"></span><br><span class="line">#查看本地文件个数：<span class="number">0</span></span><br><span class="line">$ ll</span><br><span class="line">total <span class="number">0</span></span><br><span class="line"></span><br><span class="line">#查看状态：demo2_test.txt字体绿色--&gt;本地文件已删除 ，但是本地仓库中的文件并没有删除,要清空本地仓库的内容 ，提交删除的记录</span><br><span class="line">$ git status</span><br><span class="line">On branch master</span><br><span class="line">Changes to be committed:</span><br><span class="line">  (use "git reset HEAD &lt;file&gt;..." to unstage)</span><br><span class="line"><span class="function">        deleted:    <span class="title">demo2_test.txt</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#将删除记录<span class="title">commit</span>提交至本地仓库</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">commit</span> -<span class="title">m</span> "<span class="title">commit:delete</span> <span class="title">demo2_test.txt</span>文件"</span></span><br><span class="line"><span class="function">[<span class="title">master</span> 85<span class="title">c603f</span>] <span class="title">commit:delete</span> <span class="title">demo2_test.txt</span>文件</span></span><br><span class="line"><span class="function"> 1 <span class="title">file</span> <span class="title">changed</span>, 1 <span class="title">deletion</span>(-)</span></span><br><span class="line"><span class="function"> <span class="title">delete</span> <span class="title">mode</span> 100644 <span class="title">demo2_test.txt</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#查看状态：说明本地仓库已被清空</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">status</span></span></span><br><span class="line"><span class="function"><span class="title">On</span> <span class="title">branch</span> <span class="title">master</span></span></span><br><span class="line"><span class="function"><span class="title">nothing</span> <span class="title">to</span> <span class="title">commit</span>, <span class="title">working</span> <span class="title">tree</span> <span class="title">clean</span></span></span><br></pre></td></tr></table></figure><p>回顾工作流图：<br><img src="https://upload-images.jianshu.io/upload_images/15645795-47fc912a1b1c6c62.png" alt="工作流图.png"></p><h3 id="3、本地已有仓库-ssh关联-远程空白仓库"><a href="#3、本地已有仓库-ssh关联-远程空白仓库" class="headerlink" title="3、本地已有仓库 ssh关联 远程空白仓库"></a>3、本地已有仓库 ssh关联 远程空白仓库</h3><p>1、github添加ssh keys<br><a href="https://www.jianshu.com/p/d10b71e0ce3d" target="_blank" rel="noopener">Github 添加ssh keys</a></p><p>2、github 新建仓库<br><img src="https://upload-images.jianshu.io/upload_images/15645795-ed8b875a42ea84dd.png" alt="github创建公共仓库.png"></p><p>根据空白仓库提示执行：<br><img src="https://upload-images.jianshu.io/upload_images/15645795-4b52f2b966fc70bf.png" alt="github创建公共仓库2.png"></p><p>本地已有仓库与远程空白仓库关联<br>命令：</p><blockquote><p>git remote add<name>url #name：远程仓库地址别名一般为origin ，url：远程仓库地址<br>git push -u origin master #推送到远程仓库的master分支上 -u:是强行推送(用于首次推送 ，之后推送只需：git push)</name></p></blockquote><p>命令演示：</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line">Administrator@ZhengJiaAo MINGW64 /j/testfile</span><br><span class="line">#本地创建一个文件夹</span><br><span class="line">$ <span class="built_in">mkdir</span> local_test</span><br><span class="line"></span><br><span class="line">#查看的文件夹</span><br><span class="line">$ ls</span><br><span class="line">demo/  demo2/  local_test/</span><br><span class="line">$ <span class="built_in">cd</span> local_test</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/testfile/local_test</span><br><span class="line">#追加内容到文件中</span><br><span class="line">$ <span class="built_in">echo</span> "# git_test" &gt;&gt; README.<span class="built_in">md</span></span><br><span class="line"></span><br><span class="line">#查看</span><br><span class="line">$ ls</span><br><span class="line">README.<span class="built_in">md</span></span><br><span class="line"></span><br><span class="line">#初始化git</span><br><span class="line">$ git init</span><br><span class="line">Initialized empty Git repository <span class="keyword">in</span> J:/testfile/local_test/.git/</span><br><span class="line"></span><br><span class="line">#添加文件到暂存区</span><br><span class="line">$ git add README.<span class="built_in">md</span></span><br><span class="line"><span class="function">warning: <span class="title">LF</span> <span class="title">will</span> <span class="title">be</span> <span class="title">replaced</span> <span class="title">by</span> <span class="title">CRLF</span> <span class="title">in</span> <span class="title">README.md</span>.</span></span><br><span class="line"><span class="function"><span class="title">The</span> <span class="title">file</span> <span class="title">will</span> <span class="title">have</span> <span class="title">its</span> <span class="title">original</span> <span class="title">line</span> <span class="title">endings</span> <span class="title">in</span> <span class="title">your</span> <span class="title">working</span> <span class="title">directory</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#查看状态：<span class="title">README.md</span> 是绿色说明已存到暂存区 ，再<span class="title">commit</span>提交到本地仓库</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">status</span></span></span><br><span class="line"><span class="function"><span class="title">On</span> <span class="title">branch</span> <span class="title">master</span></span></span><br><span class="line"><span class="function"><span class="title">No</span> <span class="title">commits</span> <span class="title">yet</span></span></span><br><span class="line"><span class="function"><span class="title">Changes</span> <span class="title">to</span> <span class="title">be</span> <span class="title">committed</span>:</span></span><br><span class="line"><span class="function">  (<span class="title">use</span> "<span class="title">git</span> <span class="title">rm</span> --<span class="title">cached</span> &lt;<span class="title">file</span>&gt;..." <span class="title">to</span> <span class="title">unstage</span>)</span></span><br><span class="line"><span class="function">        <span class="title">new</span> <span class="title">file</span>:   <span class="title">README.md</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#将暂存区所有内容提交到本地仓库</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">commit</span> -<span class="title">m</span> "<span class="title">first</span> <span class="title">commit</span>"</span></span><br><span class="line"><span class="function">[<span class="title">master</span> (<span class="title">root</span>-<span class="title">commit</span>) <span class="title">c02fd60</span>] <span class="title">first</span> <span class="title">commit</span></span></span><br><span class="line"><span class="function"> 1 <span class="title">file</span> <span class="title">changed</span>, 1 <span class="title">insertion</span>(+)</span></span><br><span class="line"><span class="function"> <span class="title">create</span> <span class="title">mode</span> 100644 <span class="title">README.md</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#添加远程仓库：本地仓库与远程仓库关联</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">remote</span> <span class="title">add</span> <span class="title">origin</span> <span class="title">git</span>@<span class="title">github.com:zhengjiaao</span>/<span class="title">git_test.git</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#推送到远程仓库的<span class="title">master</span>分支上 -<span class="title">u</span>:是强行推送(用于首次推送 ，之后推送只需：<span class="title">git</span> <span class="title">push</span>)</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">push</span> -<span class="title">u</span> <span class="title">origin</span> <span class="title">master</span></span></span><br><span class="line"><span class="function"><span class="title">Enumerating</span> <span class="title">objects</span>: 3, <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Counting</span> <span class="title">objects</span>: 100% (3/3), <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Writing</span> <span class="title">objects</span>: 100% (3/3), 219 <span class="title">bytes</span> | 73.00 <span class="title">KiB</span>/<span class="title">s</span>, <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Total</span> 3 (<span class="title">delta</span> 0), <span class="title">reused</span> 0 (<span class="title">delta</span> 0)</span></span><br><span class="line"><span class="function"><span class="title">To</span> <span class="title">github.com:zhengjiaao</span>/<span class="title">git_test.git</span></span></span><br><span class="line"><span class="function"> * [<span class="title">new</span> <span class="title">branch</span>]      <span class="title">master</span> -&gt; <span class="title">master</span></span></span><br><span class="line"><span class="function"><span class="title">Branch</span> '<span class="title">master</span>' <span class="title">set</span> <span class="title">up</span> <span class="title">to</span> <span class="title">track</span> <span class="title">remote</span> <span class="title">branch</span> '<span class="title">master</span>' <span class="title">from</span> '<span class="title">origin</span>'.</span></span><br></pre></td></tr></table></figure><p>上传文件后github效果图：<br><img src="https://upload-images.jianshu.io/upload_images/15645795-64e5634202fef3b2.png" alt="github创建公共仓库3.png"></p><blockquote><p>README.md 文件是我们本地”echo “# git_test” &gt;&gt; README.md”创建的 ，然后推送到github的远程仓库上</p></blockquote><h3 id="4、克隆仓库"><a href="#4、克隆仓库" class="headerlink" title="4、克隆仓库"></a>4、克隆仓库</h3><p>描述: 远程已有仓库-这个比较简单<br>流程：克隆远程已有仓库地址 –&gt; 修改文件内容 –&gt; 将修改内容推送到远程仓库<br>命令：</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">#克隆远程已有仓库地址</span><br><span class="line">$ git clone url</span><br><span class="line"></span><br><span class="line">#操作：修改文件内容</span><br><span class="line"></span><br><span class="line">#将修改内容推送到远程仓库</span><br><span class="line">$ git add</span><br><span class="line">$ git commit -m "commit 信息"</span><br><span class="line">$ git push</span><br></pre></td></tr></table></figure><p>命令演示：</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br></pre></td><td class="code"><pre><span class="line">Administrator@ZhengJiaAo MINGW64 /j/testfile</span><br><span class="line">#查看文件：有<span class="number">3</span>个文件夹</span><br><span class="line">$ ls</span><br><span class="line">demo/  demo2/  local_test/</span><br><span class="line"></span><br><span class="line">#克隆远程已有仓库地址</span><br><span class="line">$ git clone https://github.com/zhengjiaao/git_test.git</span><br><span class="line">Cloning into 'git_test'...</span><br><span class="line"><span class="function">remote: <span class="title">Enumerating</span> <span class="title">objects</span>: 3, <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">remote</span>: <span class="title">Counting</span> <span class="title">objects</span>: 100% (3/3), <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">remote</span>: <span class="title">Total</span> 3 (<span class="title">delta</span> 0), <span class="title">reused</span> 3 (<span class="title">delta</span> 0), <span class="title">pack</span>-<span class="title">reused</span> 0</span></span><br><span class="line"><span class="function"><span class="title">Unpacking</span> <span class="title">objects</span>: 100% (3/3), <span class="title">done</span>.</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#查看：多了一个文件夹 <span class="title">git_test</span></span></span><br><span class="line"><span class="function">$ <span class="title">ls</span></span></span><br><span class="line"><span class="function"><span class="title">demo</span>/  <span class="title">demo2</span>/  <span class="title">git_test</span>/  <span class="title">local_test</span>/</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#进入文件夹</span></span><br><span class="line"><span class="function">$ <span class="title">cd</span> <span class="title">git_test</span>/</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#查看：有一个<span class="title">README.md</span>文件</span></span><br><span class="line"><span class="function">$ <span class="title">ls</span></span></span><br><span class="line"><span class="function"><span class="title">README.md</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#向 <span class="title">README.md</span>文件追加内容</span></span><br><span class="line"><span class="function">$ <span class="title">echo</span> "### 测试<span class="title">k</span>克隆远程已有仓库及推送此内容到远程仓库" &gt;&gt; <span class="title">README.md</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#查看状态 ：<span class="title">README.md</span> 字体是红色：说明工作区修改后--&gt;还没有添加至暂存区</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">status</span></span></span><br><span class="line"><span class="function"><span class="title">On</span> <span class="title">branch</span> <span class="title">master</span></span></span><br><span class="line"><span class="function"><span class="title">Your</span> <span class="title">branch</span> <span class="title">is</span> <span class="title">up</span> <span class="title">to</span> <span class="title">date</span> <span class="title">with</span> '<span class="title">origin</span>/<span class="title">master</span>'.</span></span><br><span class="line"><span class="function"><span class="title">Changes</span> <span class="title">not</span> <span class="title">staged</span> <span class="title">for</span> <span class="title">commit</span>:</span></span><br><span class="line"><span class="function">  (<span class="title">use</span> "<span class="title">git</span> <span class="title">add</span> &lt;<span class="title">file</span>&gt;..." <span class="title">to</span> <span class="title">update</span> <span class="title">what</span> <span class="title">will</span> <span class="title">be</span> <span class="title">committed</span>)</span></span><br><span class="line"><span class="function">  (<span class="title">use</span> "<span class="title">git</span> <span class="title">checkout</span> -- &lt;<span class="title">file</span>&gt;..." <span class="title">to</span> <span class="title">discard</span> <span class="title">changes</span> <span class="title">in</span> <span class="title">working</span> <span class="title">directory</span>)</span></span><br><span class="line"><span class="function">        <span class="title">modified</span>:   <span class="title">README.md</span></span></span><br><span class="line"><span class="function"><span class="title">no</span> <span class="title">changes</span> <span class="title">added</span> <span class="title">to</span> <span class="title">commit</span> (<span class="title">use</span> "<span class="title">git</span> <span class="title">add</span>" <span class="title">and</span>/<span class="title">or</span> "<span class="title">git</span> <span class="title">commit</span> -<span class="title">a</span>")</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#添加 <span class="title">README.md</span>文件到暂存区</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">add</span> <span class="title">README.md</span></span></span><br><span class="line"><span class="function"><span class="title">warning</span>: <span class="title">LF</span> <span class="title">will</span> <span class="title">be</span> <span class="title">replaced</span> <span class="title">by</span> <span class="title">CRLF</span> <span class="title">in</span> <span class="title">README.md</span>.</span></span><br><span class="line"><span class="function"><span class="title">The</span> <span class="title">file</span> <span class="title">will</span> <span class="title">have</span> <span class="title">its</span> <span class="title">original</span> <span class="title">line</span> <span class="title">endings</span> <span class="title">in</span> <span class="title">your</span> <span class="title">working</span> <span class="title">directory</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#将暂存区所有内容<span class="title">commit</span>提交到本地仓库</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">commit</span> -<span class="title">m</span> "<span class="title">commit</span>: 推送到远程仓库"</span></span><br><span class="line"><span class="function">[<span class="title">master</span> 44<span class="title">a593d</span>] <span class="title">commit</span>: 推送到远程仓库</span></span><br><span class="line"><span class="function"> 1 <span class="title">file</span> <span class="title">changed</span>, 1 <span class="title">insertion</span>(+)</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#将本地<span class="title">commit</span>提交的内容 全部推送到远程仓库</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">push</span></span></span><br><span class="line"><span class="function"><span class="title">Enumerating</span> <span class="title">objects</span>: 5, <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Counting</span> <span class="title">objects</span>: 100% (5/5), <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Delta</span> <span class="title">compression</span> <span class="title">using</span> <span class="title">up</span> <span class="title">to</span> 4 <span class="title">threads</span></span></span><br><span class="line"><span class="function"><span class="title">Compressing</span> <span class="title">objects</span>: 100% (2/2), <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Writing</span> <span class="title">objects</span>: 100% (3/3), 344 <span class="title">bytes</span> | 172.00 <span class="title">KiB</span>/<span class="title">s</span>, <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Total</span> 3 (<span class="title">delta</span> 0), <span class="title">reused</span> 0 (<span class="title">delta</span> 0)</span></span><br><span class="line"><span class="function"><span class="title">To</span> <span class="title">https</span>://<span class="title">github.com</span>/<span class="title">zhengjiaao</span>/<span class="title">git_test.git</span></span></span><br><span class="line"><span class="function">   <span class="title">c02fd60</span>..44<span class="title">a593d</span>  <span class="title">master</span> -&gt; <span class="title">master</span></span></span><br></pre></td></tr></table></figure><p>推送完成看下github远程仓库效果：刷新页面<br><img src="https://upload-images.jianshu.io/upload_images/15645795-2c2850fc0dac4a35.png" alt="github创建公共仓库4.png"></p><blockquote><p>可以看出 ，我们修改的文件内容已推送到GitHub的远程仓库上</p></blockquote><h3 id="5、标签管理"><a href="#5、标签管理" class="headerlink" title="5、标签管理"></a>5、标签管理</h3><p>在版本库里打个标签 ，将来在某一时刻想要之前的版本 ，我们就可以根据标签取出想要的版本.<br>常用命令：</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">#查看所有标签名称</span><br><span class="line">$ git tag </span><br><span class="line">#查看标签的详细信息(包含commit的信息)</span><br><span class="line">$ git show tagname</span><br><span class="line">#显示标签名及其描述信息</span><br><span class="line">$ git tag -ln tagname</span><br><span class="line"></span><br><span class="line">#创建标签 ，默认是根据最新的commit打标签 ，也可以指定某个commit_Id打标签         </span><br><span class="line">$ git tag tagname</span><br><span class="line">#指定某个commitId创建标签</span><br><span class="line">git tag tagname commit_Id</span><br><span class="line">#指定提交信息,创建标签同时添加说明信息     </span><br><span class="line">$ git tag -a tagname -m "comment"</span><br><span class="line"></span><br><span class="line">#切换至指定标签 ，在某个标签上继续开发</span><br><span class="line">$ git checkout tagname</span><br><span class="line">#退出标签 ，切换到指定分支即可</span><br><span class="line">$ git checkout branchname</span><br><span class="line"></span><br><span class="line">#推送某个标签到远程   </span><br><span class="line">$ git push origin tagname</span><br><span class="line">#推送所有尚未推送的本地标签 </span><br><span class="line">$ git push origin --tags </span><br><span class="line"></span><br><span class="line">#删除本地指定标签  仅删除本地</span><br><span class="line">$ git tag -d tagname</span><br><span class="line">#删除远程仓库的指定标签</span><br><span class="line">$ git push origin -d tag tagname</span><br><span class="line"></span><br><span class="line">#获取远程某个标签信息(没有获取代码)</span><br><span class="line">$ git fetch origin tag tagname</span><br></pre></td></tr></table></figure><p><strong>选用一个项目测试标签：</strong><br>进入一个本地仓库:这里选用之前测试用到的git_test仓库</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br></pre></td><td class="code"><pre><span class="line">Administrator@ZhengJiaAo MINGW64 /j/testfile/git_test (master)</span><br><span class="line">#查看文件</span><br><span class="line">$ ls</span><br><span class="line">README.<span class="built_in">md</span></span><br><span class="line"></span><br><span class="line">#查看文件内容</span><br><span class="line">$ cat README.<span class="built_in">md</span></span><br><span class="line"># git_test</span><br><span class="line">### 测试k克隆远程已有仓库及推送此内容到远程仓库</span><br><span class="line"></span><br><span class="line">#向文件追加内容</span><br><span class="line">$ <span class="built_in">echo</span> "## 标签测试 <span class="number">1</span>" &gt;&gt; README.<span class="built_in">md</span></span><br><span class="line"></span><br><span class="line">#查看状态:README.<span class="built_in">md</span>红色 ,工作区修改了文件未添加到暂存区</span><br><span class="line">$ git status</span><br><span class="line">On branch master</span><br><span class="line">Your branch is up to <span class="built_in">date</span> with 'origin/master'.</span><br><span class="line">Changes <span class="keyword">not</span> staged <span class="keyword">for</span> commit:</span><br><span class="line">  (use "git add &lt;file&gt;..." to update what will be committed)</span><br><span class="line">  (use "git checkout -- &lt;file&gt;..." to discard changes <span class="keyword">in</span> working directory)</span><br><span class="line"><span class="function">        modified:   <span class="title">README.md</span></span></span><br><span class="line"><span class="function"><span class="title">no</span> <span class="title">changes</span> <span class="title">added</span> <span class="title">to</span> <span class="title">commit</span> (<span class="title">use</span> "<span class="title">git</span> <span class="title">add</span>" <span class="title">and</span>/<span class="title">or</span> "<span class="title">git</span> <span class="title">commit</span> -<span class="title">a</span>")</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#将修改的文件</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">add</span> <span class="title">README.md</span></span></span><br><span class="line"><span class="function"><span class="title">warning</span>: <span class="title">LF</span> <span class="title">will</span> <span class="title">be</span> <span class="title">replaced</span> <span class="title">by</span> <span class="title">CRLF</span> <span class="title">in</span> <span class="title">README.md</span>.</span></span><br><span class="line"><span class="function"><span class="title">The</span> <span class="title">file</span> <span class="title">will</span> <span class="title">have</span> <span class="title">its</span> <span class="title">original</span> <span class="title">line</span> <span class="title">endings</span> <span class="title">in</span> <span class="title">your</span> <span class="title">working</span> <span class="title">directory</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#将暂存区内容提交到本地仓库</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">commit</span> -<span class="title">m</span> "<span class="title">commit</span>:标签测试1 提交"</span></span><br><span class="line"><span class="function">[<span class="title">master</span> <span class="title">b1070cb</span>] <span class="title">commit</span>:标签测试1 提交</span></span><br><span class="line"><span class="function"> 1 <span class="title">file</span> <span class="title">changed</span>, 1 <span class="title">insertion</span>(+)</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#查看状态</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">status</span></span></span><br><span class="line"><span class="function"><span class="title">On</span> <span class="title">branch</span> <span class="title">master</span></span></span><br><span class="line"><span class="function"><span class="title">Your</span> <span class="title">branch</span> <span class="title">is</span> <span class="title">ahead</span> <span class="title">of</span> '<span class="title">origin</span>/<span class="title">master</span>' <span class="title">by</span> 1 <span class="title">commit</span>.</span></span><br><span class="line"><span class="function">  (<span class="title">use</span> "<span class="title">git</span> <span class="title">push</span>" <span class="title">to</span> <span class="title">publish</span> <span class="title">your</span> <span class="title">local</span> <span class="title">commits</span>)</span></span><br><span class="line"><span class="function"><span class="title">nothing</span> <span class="title">to</span> <span class="title">commit</span>, <span class="title">working</span> <span class="title">tree</span> <span class="title">clean</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#推送到远程仓库</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">push</span></span></span><br><span class="line"><span class="function"><span class="title">Enumerating</span> <span class="title">objects</span>: 5, <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Counting</span> <span class="title">objects</span>: 100% (5/5), <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Delta</span> <span class="title">compression</span> <span class="title">using</span> <span class="title">up</span> <span class="title">to</span> 4 <span class="title">threads</span></span></span><br><span class="line"><span class="function"><span class="title">Compressing</span> <span class="title">objects</span>: 100% (2/2), <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Writing</span> <span class="title">objects</span>: 100% (3/3), 317 <span class="title">bytes</span> | 317.00 <span class="title">KiB</span>/<span class="title">s</span>, <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Total</span> 3 (<span class="title">delta</span> 1), <span class="title">reused</span> 0 (<span class="title">delta</span> 0)</span></span><br><span class="line"><span class="function"><span class="title">remote</span>: <span class="title">Resolving</span> <span class="title">deltas</span>: 100% (1/1), <span class="title">completed</span> <span class="title">with</span> 1 <span class="title">local</span> <span class="title">object</span>.</span></span><br><span class="line"><span class="function"><span class="title">To</span> <span class="title">https</span>://<span class="title">github.com</span>/<span class="title">zhengjiaao</span>/<span class="title">git_test.git</span></span></span><br><span class="line"><span class="function">   44<span class="title">a593d</span>..<span class="title">b1070cb</span>  <span class="title">master</span> -&gt; <span class="title">master</span></span></span><br></pre></td></tr></table></figure><p>github远程仓库效果:<br><img src="https://upload-images.jianshu.io/upload_images/15645795-9e552cc69f374167.png" alt="github标签测试1.png"></p><p><strong>创建标签并推送至远程仓库:</strong><br>命令：</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">#创建本地标签</span><br><span class="line">$ git tag tagname</span><br><span class="line">#将创建的本地标签推送到远程仓库</span><br><span class="line">$ git push origin tagname</span><br></pre></td></tr></table></figure><p>命令演示：</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">Administrator@ZhengJiaAo MINGW64 /j/testfile/git_test (master)</span><br><span class="line">#查看标签</span><br><span class="line">$ git tag</span><br><span class="line"></span><br><span class="line">#创建标签</span><br><span class="line">$ git tag v1.<span class="number">0</span>.<span class="number">1</span></span><br><span class="line"></span><br><span class="line">#查看标签</span><br><span class="line">$ git tag</span><br><span class="line">v1.<span class="number">0</span>.<span class="number">1</span></span><br><span class="line"></span><br><span class="line">#将本地标签推送到github远程仓库</span><br><span class="line">$ git push origin v1.<span class="number">0</span>.<span class="number">1</span></span><br><span class="line">Total <span class="number">0</span> (delta <span class="number">0</span>), reused <span class="number">0</span> (delta <span class="number">0</span>)</span><br><span class="line">To https://github.com/zhengjiaao/git_test.git</span><br><span class="line"> * [new tag]         v1.<span class="number">0</span>.<span class="number">1</span> -&gt; v1.<span class="number">0</span>.<span class="number">1</span></span><br></pre></td></tr></table></figure><blockquote><p>标签推送到远程仓库成功!</p><p>注：当修改的代码没有commit ，也能打标签 ，但不会将工作区修改的内容打进标签 ，只有将修改的内容commit后才会打进标签中 ，然后提交标签到远程。</p><p>1、工作区修改的代码 ，没有commit ，也能打标签 ，但是标签不包含工作区修改的代码<br>2、工作区修改的代码 ，commit保存 ，可以将修改的代码打进标签 ，然后推送到远程 ，远程标签中也存在修改的代码 ，但若没有push本次commit信息到远程分支 ，远程分支是不会有commit提交信息</p></blockquote><p>github查看标签:<br><img src="https://upload-images.jianshu.io/upload_images/15645795-271cda506b9747e8.png" alt="github标签测试2.png"></p><p><strong>删除标签:</strong><br>命令：</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">#删除本地指定标签  仅删除本地</span><br><span class="line">$ git tag -d v1.<span class="number">0</span>.<span class="number">1</span></span><br><span class="line">#删除远程仓库的指定标签</span><br><span class="line">$ git push origin -d tag v1.<span class="number">0</span>.<span class="number">1</span></span><br></pre></td></tr></table></figure><p>命令演示：</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">Administrator@ZhengJiaAo MINGW64 /j/testfile/git_test (master)</span><br><span class="line">#查看标签</span><br><span class="line">$ git tag</span><br><span class="line">v1.<span class="number">0</span>.<span class="number">1</span></span><br><span class="line"></span><br><span class="line">#删除本地指定标签  仅删除本地</span><br><span class="line">$ git tag -d v1.<span class="number">0</span>.<span class="number">1</span></span><br><span class="line">Deleted tag 'v1.<span class="number">0</span>.<span class="number">1</span>' (was b1070cb)</span><br><span class="line"></span><br><span class="line">#查看标签:发现标签 v1.<span class="number">0</span>.<span class="number">1</span> 已不存在</span><br><span class="line">$ git tag</span><br><span class="line"></span><br><span class="line">#删除远程仓库的指定标签</span><br><span class="line">$ git push origin -d tag v1.<span class="number">0</span>.<span class="number">1</span></span><br><span class="line">To https://github.com/zhengjiaao/git_test.git</span><br><span class="line"> - [deleted]         v1.<span class="number">0</span>.<span class="number">1</span></span><br></pre></td></tr></table></figure><p>切换到指定标签–&gt;创建新的分支：<br>命令：</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">#切换至指定标签</span><br><span class="line">$ git checkout tagname</span><br><span class="line">#退出标签 ，切换到指定分支即可</span><br><span class="line">$ git checkout branchName</span><br><span class="line"></span><br><span class="line">#切换至指定标签 ，在某个标签上继续开发,开发完成可以创建新的分支</span><br><span class="line">$ git checkout tagname</span><br><span class="line">#这是git的最新版的命令：创建分支并切换至新分支</span><br><span class="line">$ git switch -c branchName</span><br></pre></td></tr></table></figure><h3 id="6、分支管理"><a href="#6、分支管理" class="headerlink" title="6、分支管理"></a>6、分支管理</h3><p><strong>分支操作常用命令：</strong></p><blockquote><p>git branch #显示所有本地分支, <code>*</code> 是当前分支<br>git branch -r #显示所有远程分支<br>git branch -a #显示所有分支(本地和远程)</p><p>git branch -v #显示本地分支最近一次提交信息<br>git branch -a -v #显示左右分支最后一次提交信息</p><p>git merge<name># 合并某分支到当前分支</name></p><p>git branch –merged # 已经合并的分支列表 ，git branch -d 可删除成功<br>git branch –no-merged # 未合并的分支列表 ，删除不成功 ，<code>-D</code> 选项强制删除它</p><p>git branch<name># 创建新分支<br>git checkout<name># 切换到指定分支<br>git checkout -b<name># 从本地已有的当前分支–&gt;创建新分支-&gt;切换至新分支 相当于上面两步操作<br>git checkout -b dev origin/dev # 从远程已有分支–&gt;创建新分支-&gt;切换至新分支 ，并与远程分支关联<br>git switch<name># 切换分支（推荐 ，但git需要升级到最新版本） ，没有分支不会自动创建<br>git switch -c dev # 创建并切换新分支或直接切换已有分支上 (推荐 ，但是git需要升级到最新版本)</name></name></name></name></p><p>git merge dev #合并分支</p><p>git branch -d dev #删除已经合并的分支 ，未合并的分支删除不了<br>git branch -D dev #强力删除分支 ，会丢掉未合并的内容</p></blockquote><p><strong>Git鼓励大量使用分支流程：</strong><br>查看分支：<code>git branch</code><br>创建分支：<code>git branch &lt;name&gt;</code><br>切换分支：<code>git checkout &lt;name&gt;</code>或者<code>git switch &lt;name&gt;</code><br>创建+切换分支：<code>git checkout -b &lt;name&gt;</code>或者<code>git switch -c &lt;name&gt;</code><br>合并某分支到当前分支：<code>git merge &lt;name&gt;</code><br>删除分支：<code>git branch -d &lt;name&gt;</code></p><p><strong>本地仓库的分支创建、合并、删除:</strong></p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line">#查看分支</span><br><span class="line">$ git branch</span><br><span class="line">* master</span><br><span class="line">#从当前master创建新分支dev</span><br><span class="line">$ git branch dev</span><br><span class="line">#查看分支</span><br><span class="line">$ git branch</span><br><span class="line">  dev</span><br><span class="line">* master</span><br><span class="line">#修改dev分支中test文件内容</span><br><span class="line">$ <span class="built_in">echo</span> "dev修改文件内容" &gt;&gt; test.txt</span><br><span class="line">#将修改内容添加至暂存区 ，让git版本库管理</span><br><span class="line">$ git add test.txt</span><br><span class="line">#将暂存区内容提交到本地仓库</span><br><span class="line">$ git commit -m "dev修改text内容"</span><br><span class="line">[dev <span class="number">7</span>e62af8] dev修改text内容</span><br><span class="line"> <span class="number">1</span> file changed, <span class="number">1</span> insertion(+)</span><br><span class="line">#切换至master分支</span><br><span class="line">$ git switch master</span><br><span class="line">#当前master合并dev分支内容</span><br><span class="line">$ git merge dev</span><br><span class="line">Updating <span class="number">4115</span>cf8..<span class="number">7</span>e62af8</span><br><span class="line">Fast-forward</span><br><span class="line"> test.txt | <span class="number">1</span> +</span><br><span class="line"> <span class="number">1</span> file changed, <span class="number">1</span> insertion(+)</span><br><span class="line">#查看test文件内容</span><br><span class="line">$ cat test.txt</span><br><span class="line">dev修改文件内容</span><br><span class="line"></span><br><span class="line">#删除dev分支 ，必须是已经合并成功 ，不然删除不掉dev分支 ，强力删除可以用 -D</span><br><span class="line">$ git branch -d dev</span><br><span class="line">Deleted branch dev (was <span class="number">7</span>e62af8).</span><br><span class="line">#查看分支</span><br><span class="line">$ git branch</span><br><span class="line">* master</span><br></pre></td></tr></table></figure><p>创建本地仓库分支并上传到远程仓库：</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line">#查看所有分支(本地和远程)</span><br><span class="line">$ git branch -a</span><br><span class="line">* master</span><br><span class="line">  remotes/origin/HEAD -&gt; origin/master</span><br><span class="line">  remotes/origin/master</span><br><span class="line"></span><br><span class="line">#新建本地dev分支</span><br><span class="line">$ git switch -c dev</span><br><span class="line">Switched to a new branch 'dev'</span><br><span class="line"></span><br><span class="line">#远程没有dev分支 ，本地有dev</span><br><span class="line">$ git branch -a</span><br><span class="line">* dev</span><br><span class="line">  master</span><br><span class="line">  remotes/origin/HEAD -&gt; origin/master</span><br><span class="line">  remotes/origin/master</span><br><span class="line"></span><br><span class="line">#将本地dev分支推送到远程仓库</span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/testfile/git_test (dev)</span><br><span class="line">$ git push --<span class="built_in">set</span>-upstream origin dev</span><br><span class="line">Total <span class="number">0</span> (delta <span class="number">0</span>), reused <span class="number">0</span> (delta <span class="number">0</span>)</span><br><span class="line"><span class="function">remote:</span></span><br><span class="line"><span class="function"><span class="title">remote</span>: <span class="title">Create</span> <span class="title">a</span> <span class="title">pull</span> <span class="title">request</span> <span class="title">for</span> '<span class="title">dev</span>' <span class="title">on</span> <span class="title">GitHub</span> <span class="title">by</span> <span class="title">visiting</span>:</span></span><br><span class="line"><span class="function"><span class="title">remote</span>:      <span class="title">https</span>://<span class="title">github.com</span>/<span class="title">zhengjiaao</span>/<span class="title">git_test</span>/<span class="title">pull</span>/<span class="title">new</span>/<span class="title">dev</span></span></span><br><span class="line"><span class="function"><span class="title">remote</span>:</span></span><br><span class="line"><span class="function"><span class="title">To</span> <span class="title">github.com:zhengjiaao</span>/<span class="title">git_test.git</span></span></span><br><span class="line"><span class="function"> * [<span class="title">new</span> <span class="title">branch</span>]      <span class="title">dev</span> -&gt; <span class="title">dev</span></span></span><br><span class="line"><span class="function"><span class="title">Branch</span> '<span class="title">dev</span>' <span class="title">set</span> <span class="title">up</span> <span class="title">to</span> <span class="title">track</span> <span class="title">remote</span> <span class="title">branch</span> '<span class="title">dev</span>' <span class="title">from</span> '<span class="title">origin</span>'.</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#推送成功 ：<span class="title">remotes</span>/<span class="title">origin</span>/<span class="title">dev</span></span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">branch</span> -<span class="title">a</span></span></span><br><span class="line"><span class="function">* <span class="title">dev</span></span></span><br><span class="line"><span class="function">  <span class="title">master</span></span></span><br><span class="line"><span class="function">  <span class="title">remotes</span>/<span class="title">origin</span>/<span class="title">HEAD</span> -&gt; <span class="title">origin</span>/<span class="title">master</span></span></span><br><span class="line"><span class="function">  <span class="title">remotes</span>/<span class="title">origin</span>/<span class="title">dev</span></span></span><br><span class="line"><span class="function">  <span class="title">remotes</span>/<span class="title">origin</span>/<span class="title">master</span></span></span><br></pre></td></tr></table></figure><p>删除仓库分支：</p><blockquote><p>git branch -d<branch-name>删除分支<br>git push origin –delete<branch-name>删除远程分支</branch-name></branch-name></p></blockquote><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">#查看所有分支</span><br><span class="line">$ git branch -a</span><br><span class="line">* dev</span><br><span class="line">  master</span><br><span class="line">  remotes/origin/HEAD -&gt; origin/master</span><br><span class="line">  remotes/origin/dev</span><br><span class="line">  remotes/origin/master</span><br><span class="line">#删除远程仓库分支</span><br><span class="line">$ git push origin --delete dev</span><br><span class="line">To github.com:zhengjiaao/git_test.git</span><br><span class="line"> - [deleted]         dev</span><br><span class="line">#查看所有分支：发现远程仓库已经没有dev分支</span><br><span class="line">$ git branch -a</span><br><span class="line">* dev</span><br><span class="line">  master</span><br><span class="line">  remotes/origin/HEAD -&gt; origin/master</span><br><span class="line">  remotes/origin/master</span><br><span class="line">#切换到master分支</span><br><span class="line">$ git switch master</span><br><span class="line">Switched to branch 'master'</span><br><span class="line">Your branch is up to <span class="built_in">date</span> with 'origin/master'.</span><br><span class="line">#删除本地分支 ，注意dev分支要是已合并的分支 ，不然删除报错 ，可以用 -D 强力删除 ，但会丢失dev开发的代码 ，所以要先合并分支 ，再删除分支</span><br><span class="line">$ git branch -d dev</span><br><span class="line">Deleted branch dev (was b1070cb).</span><br><span class="line">#查看所有分支：发现本仓库已没有dev分支</span><br><span class="line">$ git branch -a</span><br><span class="line">* master</span><br><span class="line">  remotes/origin/HEAD -&gt; origin/master</span><br><span class="line">  remotes/origin/master</span><br></pre></td></tr></table></figure><p>###7、远程仓库管理</p><p>远程仓库添加、重命名、删除等操作。<br>命令：</p><pre><code>#查看远程仓库别名或路径
$ git remote
$ git remote -v

#删除关联的远程仓库路径
$ git remote rm origin

#添加远程仓库：origin远程仓库别名 ，url远程仓库地址
$ git remote add origin url

#修改远程仓库别名
$ git remote rename origin oldorigin
$ git remote
oldorigin

#添加多个远程仓库
$ git remote add origin url
$ git remote
oldorigin
origin</code></pre><p>本地仓库和远程仓库：</p><pre><code>#本地删除远程仓库
$ git remote rm origin
#发现已经没有远程仓库
$ git remote

#添加远程仓库
$ git remote add origin git@github.com:zhengjiaao/git_test1.git
#查看远程仓库
$ git remote
origin

#远程仓库重命名
$ git remote rename origin oldorigin
$ git remote
oldorigin

#添加多个远程仓库
$  git remote add origin git@github.com:zhengjiaao/git_test2.git
$ git remote
oldorigin
origin</code></pre><p>多个远程仓库推送和下拉需要指定仓库别名 如：</p><blockquote><p>git pull origin master<br>git pull oldorigin master<br>git push origin master<br>git push oldorigin master</p></blockquote><p>一次推送到多个远程仓库：<br>上面是不是感觉麻烦 ，两个远程仓库要推送两次 ，也可以一次推送到多个远程仓库：<br>命令：</p><pre><code>#url 是第二个(或大于第二个)远程仓库
$ git remote set-url --add origin url</code></pre><p>命令演示：</p><pre><code>#有一个远程仓库
$ git remote -v
origin  git@github.com:zhengjiaao/git_test.git (fetch)
origin  git@github.com:zhengjiaao/git_test.git (push)

#添加第二个远程仓库
$ git remote set-url --add origin git@github.com:zhengjiaao/git_test2.git
#查看发现多了一个远程仓库 ，别名都是origin 一致的
$ git remote -v
origin  git@github.com:zhengjiaao/git_test.git (fetch)
origin  git@github.com:zhengjiaao/git_test.git (push)
origin  git@github.com:zhengjiaao/git_test2.git (push)</code></pre><p>一次推送到多个远程仓库 如：</p><blockquote><p>git push origin master</p></blockquote></div><div class="popular-posts-header"><p style="font-size:18px;color:red;margin:0 0 5px 0">相关文章推荐：</p></div><ul class="popular-posts"><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\832089102.html" rel="bookmark">Git-下拉和上传项目</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\2127647912.html" rel="bookmark">Git-远程仓库及分支管理</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\2439716409.html" rel="bookmark">GitHub上创建自己的Maven仓库并引用</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\3963925067.html" rel="bookmark">Github-添加ssh-keys</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\3395771604.html" rel="bookmark">Git使用</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\39002084.html" rel="bookmark">git-同步远程仓库A和远程仓库B</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\2149577032.html" rel="bookmark">github-fork后两个仓库之间如何同步代码</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\426039077.html" rel="bookmark">git-stash-用法</a></div></li></ul><div><div style="text-align:center;color:#ccc;font-size:14px">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div></div><div class="reward-container"><div><p style="font-size:14px;color:#34495e;margin:0 0 5px 0">赞赏一下吧～ 还可以关注公众号订阅最新内容</p></div><button disable="enable" onclick="var qr = document.getElementById(&quot;qr&quot;); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">打赏</button><div id="qr" style="display:none"><div style="display:inline-block"><img src="/my-images/WeChat.png" alt="宇宙小神特别萌 微信支付"><p>微信支付</p></div><div style="display:inline-block"><img src="/my-images/Alipay.png" alt="宇宙小神特别萌 支付宝"><p>支付宝</p></div></div></div><footer class="post-footer"><div class="post-tags"><a href="/tags/Git/" rel="tag"><i class="fa fa-tag"></i> Git</a></div><div class="post-nav"><div class="post-nav-item"><a href="/posts/515071078.html" rel="prev" title="Windows-下-Zookeeper-单机模式和伪分布式模式安装"><i class="fa fa-chevron-left"></i> Windows-下-Zookeeper-单机模式和伪分布式模式安装</a></div><div class="post-nav-item"><a href="/posts/703432472.html" rel="next" title="redis安装及基本语法">redis安装及基本语法 <i class="fa fa-chevron-right"></i></a></div></div></footer></article></div></div><div class="comments" id="valine-comments"></div><script>window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }</script></div><div class="toggle sidebar-toggle"><span class="toggle-line toggle-line-first"></span> <span class="toggle-line toggle-line-middle"></span> <span class="toggle-line toggle-line-last"></span></div><aside class="sidebar"><div class="sidebar-inner"><ul class="sidebar-nav motion-element"><li class="sidebar-nav-toc">文章目录</li><li class="sidebar-nav-overview">站点概览</li></ul><div class="post-toc-wrap sidebar-panel"><div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#1、git-安装、升级、简单测试"><span class="nav-text">1、git 安装、升级、简单测试</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#git升级："><span class="nav-text">git升级：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#配置git的户信息："><span class="nav-text">配置git的户信息：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#git本地测试："><span class="nav-text">git本地测试：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#解决git-bash-终端显示中文乱码"><span class="nav-text">解决git bash 终端显示中文乱码</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2、git工作流"><span class="nav-text">2、git工作流</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#前提：查看commit日志："><span class="nav-text">前提：查看commit日志：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#1、文件commit本地仓库"><span class="nav-text">1、文件commit本地仓库</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2、将暂存区回退到工作区-回退修改内容"><span class="nav-text">2、将暂存区回退到工作区 回退修改内容</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3、把最近一次commit撤回到暂存区"><span class="nav-text">3、把最近一次commit撤回到暂存区</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4、回退本地版本库commit提交"><span class="nav-text">4、回退本地版本库commit提交</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#5、回退已push到远程版本库commit提交"><span class="nav-text">5、回退已push到远程版本库commit提交</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#6、清空或删除本地仓库文件"><span class="nav-text">6、清空或删除本地仓库文件</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3、本地已有仓库-ssh关联-远程空白仓库"><span class="nav-text">3、本地已有仓库 ssh关联 远程空白仓库</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4、克隆仓库"><span class="nav-text">4、克隆仓库</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5、标签管理"><span class="nav-text">5、标签管理</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6、分支管理"><span class="nav-text">6、分支管理</span></a></li></ol></div></div><div class="site-overview-wrap sidebar-panel"><div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person"><img class="site-author-image" itemprop="image" alt="宇宙小神特别萌" src="/my-images/avatar.gif"><p class="site-author-name" itemprop="name">宇宙小神特别萌</p><div class="site-description" itemprop="description">人生就是一次幸运的旅行！</div></div><div class="site-state-wrap motion-element"><nav class="site-state"><div class="site-state-item site-state-posts"><a href="/archives/"><span class="site-state-item-count">116</span> <span class="site-state-item-name">文章</span></a></div><div class="site-state-item site-state-tags"><a href="/tags/"><span class="site-state-item-count">27</span> <span class="site-state-item-name">标签</span></a></div></nav></div><div class="links-of-author motion-element"><span class="links-of-author-item"><a href="https://github.com/zhengjiaao" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;zhengjiaao" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a> </span><span class="links-of-author-item"><a href="https://www.jianshu.com/u/70d69269bd09" title="简书 → https:&#x2F;&#x2F;www.jianshu.com&#x2F;u&#x2F;70d69269bd09" rel="noopener" target="_blank"><i class="fa fa-fw fa-book"></i>简书</a> </span><span class="links-of-author-item"><a href="/atom.xml" title="RSS → &#x2F;atom.xml"><i class="fa fa-fw fa-rss"></i>RSS</a></span></div><div class="links-of-blogroll motion-element"><div class="links-of-blogroll-title"><i class="fa fa-fw fa-link"></i> 推荐阅读</div><ul class="links-of-blogroll-list"><li class="links-of-blogroll-item"><a href="https://github.com/spring-projects" title="https:&#x2F;&#x2F;github.com&#x2F;spring-projects" rel="noopener" target="_blank">spring-projects</a></li><li class="links-of-blogroll-item"><a href="http://www.alloyteam.com/nav/" title="http:&#x2F;&#x2F;www.alloyteam.com&#x2F;nav&#x2F;" rel="noopener" target="_blank">Web前端导航</a></li><li class="links-of-blogroll-item"><a href="http://www.chuangzaoshi.com/code" title="http:&#x2F;&#x2F;www.chuangzaoshi.com&#x2F;code" rel="noopener" target="_blank">创造狮导航</a></li></ul></div></div></div></aside><div id="sidebar-dimmer"></div></div></main><footer class="footer"><div class="footer-inner"><div class="copyright">&copy; <span itemprop="copyrightYear">2020</span> <span class="with-love"><i class="fa fa-heart"></i> </span><span class="author" itemprop="copyrightHolder">宇宙小神特别萌</span> <span class="post-meta-divider">|</span> <span class="post-meta-item-icon"><i class="fa fa-area-chart"></i> </span><span title="站点总字数">1.2m</span> <span class="post-meta-divider">|</span> <span class="post-meta-item-icon"><i class="fa fa-coffee"></i> </span><span title="站点阅读时长">17:41</span></div><div class="busuanzi-count"><script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><span class="post-meta-item" id="busuanzi_container_site_uv" style="display:none"><span class="post-meta-item-icon"><i class="fa fa-user"></i> </span><span class="site-uv" title="总访客量"><span id="busuanzi_value_site_uv"></span> </span></span><span class="post-meta-divider">|</span> <span class="post-meta-item" id="busuanzi_container_site_pv" style="display:none"><span class="post-meta-item-icon"><i class="fa fa-eye"></i> </span><span class="site-pv" title="总访问量"><span id="busuanzi_value_site_pv"></span></span></span></div></div></footer></div><script src="//cdn.jsdelivr.net/npm/animejs@3.1.0/lib/anime.min.js"></script><script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script><script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script><script src="//cdnjs.cloudflare.com/ajax/libs/velocity/1.2.1/velocity.min.js"></script><script src="//cdnjs.cloudflare.com/ajax/libs/velocity/1.2.1/velocity.ui.min.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/schemes/muse.js"></script><script src="/js/next-boot.js"></script><script src="/js/bookmark.js"></script><script>!function(){var t=document.createElement("script"),e=window.location.protocol.split(":")[0];t.src="https"===e?"https://zz.bdstatic.com/linksubmit/push.js":"http://push.zhanzhang.baidu.com/push.js";var s=document.getElementsByTagName("script")[0];s.parentNode.insertBefore(t,s)}()</script><script src="/js/local-search.js"></script><script>NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//cdnjs.cloudflare.com/ajax/libs/valine/1.3.10/Valine.min.js', () => {
    <!--var GUEST = ['nick', 'mail', 'link'];-->
    var GUEST = ['nick', 'mail'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el: '#valine-comments',
      verify: false,
      notify: false,
      appId: 'OuyHeA0XGL8hK4vgbqL0iERx-gzGzoHsz',
      appKey: 'L58VglKmWULcGK2W2AN7kWzM',
      placeholder: "留下邮箱，有回复时你将收到提醒，邮箱不会被公开。",
      avatar: 'wavatar',
      meta: guest,
      pageSize: '10' || 10,
      visitor: true,
      lang: 'zh-cn' || 'zh-cn',
      path: location.pathname,
      recordIP: true,
      serverURLs: ''
    });
  }, window.Valine);
});</script><script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({pluginRootPath:"live2dw/",pluginJsPath:"lib/",pluginModelPath:"assets/",tagMode:!1,model:{jsonPath:"/live2dw/assets/wanko.model.json"},display:{position:"right",width:150,height:300},mobile:{show:!1},log:!1})</script></body><script type="text/javascript" src="/js/src/activetitle.js"></script></html><!-- rebuild by neat -->